/*********************\
* Author:Dzlua
* QQ:505544956
* Time:2017/04/09
\**********************/
#ifndef __LUA_WINDOW_H__
#define __LUA_WINDOW_H__
#pragma once

#include "../Base/LuaHelper.h"
#include <spdui/spdui.h>

namespace DuiLib {

class LuaWindow : public LuaClassBase
{
    SDLUA_CLASS_DECLARE(LuaWindow);

    int SetEvent(LuaState *L);
    int RemoveEvent(LuaState *L);
    
    //=================================================//
    int /*HWND*/ GetHWND();
    int Create(LuaState *L);
    int ShowWindow(LuaState *L);
    UINT ShowModal();
    int Close(LuaState *L);
    void CenterWindow();
    void SetIcon(UINT nRes);
    int SendMessage(LuaState *L);
    int PostMessage(LuaState *L);
    int ResizeClient(LuaState *L);

    //=================================================//
    /*bool IsUpdateNeeded();
    void NeedUpdate();*/
    int Invalidate(LuaState *L);
    
    int GetName(LuaState* L);
    int /*HDC*/ GetPaintDC();
    int /*HWND*/ GetPaintWindow();
    int/*HWND*/ GetTooltipWindow();

    int GetMousePos(LuaState *L);
    int GetClientSize(LuaState *L);
    int GetInitSize(LuaState *L);
    void SetInitSize(int cx, int cy);
    int GetSizeBox(LuaState *L);
    int SetSizeBox(LuaState *L);
    int GetCaptionRect(LuaState *L);
    int SetCaptionRect(LuaState *L);
    
    int GetRoundCorner(LuaState *L);
    void SetRoundCorner(int cx, int cy);
    int GetMinInfo(LuaState *L);
    void SetMinInfo(int cx, int cy);
    int GetMaxInfo(LuaState *L);
    void SetMaxInfo(int cx, int cy);
    bool IsShowUpdateRect();
    void SetShowUpdateRect(bool show);

    BYTE GetOpacity();
    void SetOpacity(BYTE nOpacity);
    bool IsLayered();
    void SetLayered(bool bLayered);
    int GetLayeredInset(LuaState *L);
    int SetLayeredInset(LuaState *L);
    BYTE GetLayeredOpacity();
    void SetLayeredOpacity(BYTE nOpacity);

    int GetShadow(LuaState *L);

    /*bool ShowCaret(bool bShow);
    bool SetCaretPos(CRichEditUI* obj, int x, int y);
    CRichEditUI* GetCurrentCaretObject();
    bool CreateCaret(HBITMAP hBmp, int nWidth, int nHeight);
    void DrawCaret(HDC hDC, const RECT& rcPaint);*/
    
    void SetUseGdiplusText(bool bUse);
    bool IsUseGdiplusText();
    void SetGdiplusTextRenderingHint(int trh);
    int GetGdiplusTextRenderingHint();

    bool IsForceUseSharedRes();
    void SetForceUseSharedRes(bool bForce);

    //void DeletePtr(void* ptr);

    DWORD GetDefaultDisabledColor();
    int SetDefaultDisabledColor(LuaState *L);
    DWORD GetDefaultFontColor();
    int SetDefaultFontColor(LuaState *L);
    DWORD GetDefaultLinkFontColor();
    int SetDefaultLinkFontColor(LuaState *L);
    DWORD GetDefaultLinkHoverFontColor();
    int SetDefaultLinkHoverFontColor(LuaState *L);
    DWORD GetDefaultSelectedBkColor();
    int SetDefaultSelectedBkColor(LuaState *L);
    /*TFontInfo* GetDefaultFontInfo();
    void SetDefaultFont(LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bShared = false);
    DWORD GetCustomFontCount(bool bShared = false) const;
    void AddFontArray(LPCTSTR pstrPath);
    HFONT AddFont(int id, LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bShared = false);
    HFONT GetFont(int id);
    HFONT GetFont(LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic);
    int GetFontIndex(HFONT hFont, bool bShared = false);
    int GetFontIndex(LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bShared = false);
    void RemoveFont(HFONT hFont, bool bShared = false);
    void RemoveFont(int id, bool bShared = false);
    void RemoveAllFonts(bool bShared = false);
    TFontInfo* GetFontInfo(int id);
    TFontInfo* GetFontInfo(HFONT hFont);*/

    /*const TImageInfo* GetImage(LPCTSTR bitmap);
    const TImageInfo* GetImageEx(LPCTSTR bitmap, LPCTSTR type = NULL, DWORD mask = 0, bool bUseHSL = false, HINSTANCE instance = NULL);
    const TImageInfo* AddImage(LPCTSTR bitmap, LPCTSTR type = NULL, DWORD mask = 0, bool bUseHSL = false, bool bShared = false, HINSTANCE instance = NULL);
    const TImageInfo* AddImage(LPCTSTR bitmap, HBITMAP hBitmap, int iWidth, int iHeight, bool bAlpha, bool bShared = false);
    void RemoveImage(LPCTSTR bitmap, bool bShared = false);
    void RemoveAllImages(bool bShared = false);*/

    void ReloadImages();

    /*const TDrawInfo* GetDrawInfo(LPCTSTR pStrImage, LPCTSTR pStrModify);
    void RemoveDrawInfo(LPCTSTR pStrImage, LPCTSTR pStrModify);
    void RemoveAllDrawInfos();

    void AddDefaultAttributeList(LPCTSTR pStrControlName, LPCTSTR pStrControlAttrList, bool bShared = false);
    LPCTSTR GetDefaultAttributeList(LPCTSTR pStrControlName) const;
    bool RemoveDefaultAttributeList(LPCTSTR pStrControlName, bool bShared = false);
    void RemoveAllDefaultAttributeList(bool bShared = false);

    void AddWindowCustomAttribute(LPCTSTR pstrName, LPCTSTR pstrAttr);
    LPCTSTR GetWindowCustomAttribute(LPCTSTR pstrName) const;
    bool RemoveWindowCustomAttribute(LPCTSTR pstrName);
    void RemoveAllWindowCustomAttribute();

    void AddStyle(LPCTSTR pName, LPCTSTR pStyle, bool bShared = false);
    LPCTSTR GetStyle(LPCTSTR pName) const;
    BOOL RemoveStyle(LPCTSTR pName, bool bShared = false);
    const CStdStringPtrMap& GetStyles(bool bShared = false) const;
    void RemoveAllStyle(bool bShared = false);

    const TImageInfo* GetImageString(LPCTSTR pStrImage, LPCTSTR pStrModify = NULL);

    bool InitDragDrop();
    virtual bool OnDrop(FORMATETC* pFmtEtc, STGMEDIUM& medium,DWORD *pdwEffect);

    bool AttachDialog(CControlUI* pControl);
    bool InitControls(CControlUI* pControl, CControlUI* pParent = NULL);
    void ReapObjects(CControlUI* pControl);

    bool AddOptionGroup(LPCTSTR pStrGroupName, CControlUI* pControl);
    CStdPtrArray* GetOptionGroup(LPCTSTR pStrGroupName);
    void RemoveOptionGroup(LPCTSTR pStrGroupName, CControlUI* pControl);
    void RemoveAllOptionGroups();*/

    int GetFocus(LuaState *L);
    int SetFocus(LuaState *L);
    int SetFocusNeeded(LuaState *L);

    int SetNextTabControl(LuaState *L);

    int SetTimer(LuaState *L);
    int KillTimer(LuaState *L);
    void RemoveAllTimers();

    void SetCapture();
    void ReleaseCapture();
    bool IsCaptured();

    bool IsPainting();
    void SetPainting(bool bIsPainting);

    //bool AddNotifier(INotifyUI* pControl);
    //bool RemoveNotifier(INotifyUI* pControl);   
    //void SendNotify(TNotifyUI& Msg, bool bAsync = false);
    int SendNotify(LuaState *L);

    /*bool AddPreMessageFilter(IMessageFilterUI* pFilter);
    bool RemovePreMessageFilter(IMessageFilterUI* pFilter);

    bool AddMessageFilter(IMessageFilterUI* pFilter);
    bool RemoveMessageFilter(IMessageFilterUI* pFilter);

    int GetPostPaintCount() const;
    bool IsPostPaint(CControlUI* pControl);
    bool AddPostPaint(CControlUI* pControl);
    bool RemovePostPaint(CControlUI* pControl);
    bool SetPostPaintIndex(CControlUI* pControl, int iIndex);

    int GetPaintChildWndCount() const;
    bool AddPaintChildWnd(HWND hChildWnd);
    bool RemovePaintChildWnd(HWND hChildWnd);

    void AddDelayedCleanup(CControlUI* pControl);

    bool AddTranslateAccelerator(ITranslateAccelerator *pTranslateAccelerator);
    bool RemoveTranslateAccelerator(ITranslateAccelerator *pTranslateAccelerator);
    bool TranslateAccelerator(LPMSG pMsg);*/

    int GetRoot(LuaState *L);
    //name or {x,y}(point)
    int FindControl(LuaState *L);
    //name or {x,y}(point)
    int FindSubControl(LuaState *L);
    int FindSubControlByClass(LuaState *L);
    //CStdPtrArray* FindSubControlsByClass(CControlUI* pParent, LPCTSTR pstrClass);

    /*CDPI* GetDPIObj();
    void ResetDPIAssets();
    void RebuildFont(TFontInfo* pFontInfo);
    void SetDPI(int iDPI);

    bool MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& lRes);
    bool PreMessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& lRes);
    void UsedVirtualWnd(bool bUsed);
    */
    //=================================================//
    LONG GetStyle();
    int IsStaticControl(LuaState *L);
    //xml or str
    int BuildWindow(LuaState *L);
    //xml or str
    int BuildControl(LuaState *L);
    void Minimize();
    void Maximize();
    void Restore();
};

}

#endif //__LUA_WINDOW_H__